<template>
  <div class="profile-day">
    <van-datetime-picker
        v-model="currentDate"
        type="date"
        title="选择年月日"
        :min-date="minDate"
        :max-date="maxDate"
        @cancel="$emit('close')"
        @confirm="onConfirm"
    />
  </div>
</template>

<script>
import {updateUserProfile} from "@/api/user";
import dayjs from 'dayjs'

export default {
  name: "profileDay",
  props:{
    birthday:{
      type:String,
      required:true
    }
  },
  data(){
    return{
        minDate: new Date(1990, 0, 1),
        maxDate: new Date(),
        currentDate: new Date(this.birthday)
    }
  },
  methods:{
    async onConfirm() {
      this.$toast.loading({
        message:'保存中',
        forbidClick:true
      })
      const date=dayjs(this.currentDate).format('YYYY-MM-DD')
      try {
        await updateUserProfile('birthday',date)
        this.$toast.success('保存成功')
        this.$emit('update-birthday',date)
        this.$emit('close')
      }catch (err){
      }
    },
  }
}
</script>

<style scoped>

</style>